package greedy.总结.基础;

import java.util.HashMap;
import java.util.Map;

public class leetcode1400构造K个回文字符串 {
    public boolean canConstruct(String s, int k) {
        int length = s.length();
        if (length < k) {
            return false;
        }
        Map<Character, Boolean> map = new HashMap<>();
        for (int i = 0; i < length; i++) {
            if (!map.containsKey(s.charAt(i))) {
                map.put(s.charAt(i), true);
            } else {
                map.put(s.charAt(i), !map.get(s.charAt(i)));
            }
        }
        int count = 0;
        for (Character character : map.keySet()) {
            if (map.get(character)) {
                count++;
            }
        }
        return length % 2 == count % 2;
    }
}
